package com.liqi.web.controller.device;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liqi.common.annotation.Log;
import com.liqi.common.constant.UserConstants;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.domain.AjaxResult;
import com.liqi.common.core.domain.R;
import com.liqi.common.core.page.TableDataInfo;
import com.liqi.common.enums.BusinessType;
import com.liqi.common.utils.DateUtils;
import com.liqi.common.utils.StringUtils;
import com.liqi.common.utils.excel.ExcelUtils;
import com.liqi.common.utils.poi.ExcelUtil;
import com.liqi.common.utils.uuid.GenerateCodeUtils;
import com.liqi.device.domain.DvBrand;
import com.liqi.device.domain.DvDevice;
import com.liqi.device.domain.DvModule;
import com.liqi.device.domain.TWorkingCalendar;
import com.liqi.device.service.IDvBrandService;
import com.liqi.device.service.IDvDeviceService;
import com.liqi.device.service.IDvModuleService;
import com.liqi.device.service.TWorkingCalendarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.*;

/**
 * 品牌Controller
 *
 * @author ruoyi
 * @date 2022-02-11
 */
@Api(tags = "初始化当年的工作日")
@RestController
@RequestMapping("/TWorkingCalendar")
public class TWorkingCalendarController extends BaseController {


    @Autowired
    private TWorkingCalendarService calendarInfoService;


    @ApiOperation("初始化当年工作日")
    @PostMapping("/init")
    public R init() {


        LocalDate localDate = LocalDate.now();

        TWorkingCalendar tWorkingCalendar = calendarInfoService.getOne(Wrappers.lambdaQuery(TWorkingCalendar.class).eq(TWorkingCalendar::getCalendarDate, localDate));
        if (tWorkingCalendar == null) {
            List<TWorkingCalendar> resrltCalendarInfos = new ArrayList<>();
            List<Integer> list = Arrays.asList(2, 5, 8, 11);
            list.forEach(o -> {
                resrltCalendarInfos.addAll(calendarInfoService.resolveCalendarInfo(String.valueOf(localDate.getYear()), String.valueOf(o)));
            });
            calendarInfoService.saveBatch(resrltCalendarInfos);
        }
        return R.ok();
    }
}


